﻿//Class retrieves the value of the Language selected to be put into the Google translate URL.
//The languages are stored in a text file in the current program directory.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace OCRGUI2008
{
    public class cmbLangSelect
    {
        public cmbLangSelect()
        {

        }

        //Primary function to retrieve value of languages for Google Translate.
        //Function is used with the From and To comboboxes used to select the language translation.

        public string fromtoLang(string abbrLang) // abbrLang is the language name in the text file
        {
            string[] lineOfContents = File.ReadAllLines("GoogleLanguages\\GoogleLangs.txt");  //Opens the GoogleLangs.txt file and stores it into a C# string array

            string result = ""; //result will be the return value for the selected language


            //Loops through lineOfContents string array to get each language name and value
            foreach (var line in lineOfContents)
            {
                string[] tokens = line.Split('\t'); //Splits the string line with the tab delimter

                if (string.Compare(tokens[0], abbrLang) == 0) //compares each name with the abbrLang to determine which language to select 
                {
                    result = tokens[1]; // Stores the value of the Language
                }
            } //for each

            return result; //Returns the Google Value of the Language
        }
    }
}
